﻿using BasicInformation.API.Application.Command.VehicleCommand;
using BasicInformation.Infrastructure.Iml;
using BasicInformation.Infrastructure.Interface;
using MediatR;

namespace BasicInformation.API.Application.CommandHandler.VehicleCommandHandler
{
    public class VehicleBatchDeleteCommandHandler : IRequestHandler<VehicleBatchDeleteCommand, int>
    {
        private readonly IVehicleRepository vehicleRepository;

        public VehicleBatchDeleteCommandHandler(IVehicleRepository vehicleRepository)
        {
            this.vehicleRepository = vehicleRepository;
        }

        public async Task<int> Handle(VehicleBatchDeleteCommand request, CancellationToken cancellationToken)
        {
            var Id = request.Ids.Split(',').Select(x => Convert.ToInt32(x)).ToArray();
            var list = await vehicleRepository.GetListInfo(x => Id.Contains(x.Id));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await vehicleRepository.UpdateRange(list);
        }
    }
}
